// pages/auth/index.js
import { request } from "../../request/index.js";

Page({

  //获取用户信息
  async handleGetUserInfo(e){
    try {
      const {encryptedData,rawData,iv,signature}=e.detail;
      const {code}="";
      //获取小程序登录成功后的code
      wx.login({
        timeout:10000,
        success: (result) =>{
          const {code}=result;
          //封装传递的参数
          this.code=code;
        }
      });
      const loginParams={encryptedData,rawData,iv,signature,code};
      //发送请求 获取用户的token
      const result=await request({url:"/users/wxlogin",data:loginParams,method:"post"});
      // console.log(res);
      wx.setStorageSync("token", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo");
      wx.navigateBack({
        delta: 1
      }); 
    } catch (error) {
      console.log(error);
    }
    
  }
})